// 导入请求模块
const indexHttp = require("../../../utils/indexHttp")
Page({
  data: {
    banner: [],
    skip: 0
  },
  async onLoad() {
    // 请求轮播数据
    var banners = await indexHttp.getBannerHttp();
    this.setData({
      banner: banners.data.res
    })
    //请求新闻模块数据
    var skip = this.data.skip;
    var News = await indexHttp.getNewHttp(skip);
    this.setData({
      New: News.data.res
    })
  },
  // 新闻模块上拉刷新
  onReachBottom: async function () {
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    var skip = this.data.skip;
    skip += 5;
    if (skip == 25) {
      skip = 0
    }
    var New = this.data.New;
    setTimeout(async () => {
      var res = await indexHttp.getNewHttp(skip);
      New = res.data.res
      wx.hideLoading()
      wx.pageScrollTo({
        scrollTop: 300, // 滚动到的位置（距离顶部 px）
        duration: 0 //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
      })
      this.setData({
        New,
        skip
      })
    }, 1000)
    
    
  },
  // 页面跳转 四个模块分别跳转
  toCulture() {
    wx.navigateTo({
      url: '../../cultures/culture/culture',
    })
  },
  toAsked() {
    wx.navigateTo({
      url: '../../asks/asked/asked',
    })
  },
  toFood() {
    wx.navigateTo({
      url: '../../foods/food/food',
    })
  },
  toTrip() {
    wx.navigateTo({
      url: '../../trips/trip/trip',
    })
  },
  toDetail(e) {
    var {
      aid
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `../indexNewDetail/indexNewDetail?id=${aid}`,
    })
  }
})